public class Recursion {
    public static void main(String[] args) {
        System.out.println(fib2(5));
    }
    public static int fib2(int n) {
        if(n == 1 || n == 2 ) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 1;
        for (int i = 3;i <= n;i++){
            f3 = f2 + f1;
            f1 = f2;
            f2 = f3;
        }
        return f3;

    }
    public static int fib(int n) {
        if(n == 1) {
            return 0;
        }
        if (n == 2) {
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }
    public static void print(int n) {
        if(n < 10 ) {
            System.out.println(n % 10);
            return;
        }

        print(n / 10);
        System.out.println(n % 10);
    }
    public static void main2(String[] args) {
        print(123);
    }
    public static int fuc(int a) {
        if(a == 1)//终止条件
        {
            return 1;
        }
        return a * fuc(a -1 );
    }
    public static void main1(String[] args) {
        System.out.println(fuc(10));
    }
}
